import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib as mpl
from sklearn.preprocessing import StandardScaler
from scipy.stats import zscore
mpl.use('TkAgg')

x = pd.read_csv("data/factor.csv", index_col=0)
#
PM = pd.read_csv("data/PM.csv", index_col=0)
# AQI = pd.read_csv("data/AQI.csv", index_col=0)
# print(x)
# x["PM10"] = zscore(x["PM10"])
# x["O3"]	= zscore(x["O3"])
# x["SO2"] = zscore(x["SO2"])
# x["NO2"] = zscore(x["NO2"])
# x["CO"]	= zscore(x["CO"])
# x["precipitation"] = zscore(x["precipitation"])
# x["air_pressure"] = zscore(x["air_pressure"])
# x["wind_speed"]	= zscore(x["wind_speed"])
# x["temperature"] = zscore(x["temperature"])
# x["humidity"] = zscore(x["humidity"])
# print(x)
# x.to_csv("data/factor_pred.csv")

# print(AQI)
# x_1 = x.drop(['Year'], axis=1)
# x.info()
# y.info()

# print(x)
# print(y)

# 绘制影响PM2.5因素两两之间相关系数热力图
# plt.figure(figsize=(16, 16))
# sns.heatmap(x.corr(method="spearman"), annot=True, cmap='PuBu', xticklabels=True, yticklabels=True)
# plt.savefig("img/heatmap.png", dpi=300)
# air_pressure 和 temperature强负相关

# 绘制PM2.5与时间的折线图
PM.index.name = 'Days'
# plt.figure(figsize=(16, 9), dpi=300)
# sns.lineplot(data=PM, x="Days", y="PM2.5")
# plt.savefig("img/PM2.5-Days.png")

# 绘制Month-PM2.5图像
# x_2 = pd.concat([x, PM],axis=1)
# result = x_2.groupby(["Year", "Month"])["PM2.5"].agg("mean")
# print(x_2)
# # print(result)
# result.to_csv("data/PM2.5-Month.csv")
# result = result.reset_index() # 转换为长格式
# sns.set_style("darkgrid") # 设置图的风格为深色网格
# plt.figure(figsize=(16, 9), dpi=300)
# # sns.color_palette("tab10", 12) # 设置图的调色板为Set2
# sns.lineplot(data=result, x="Year", y="PM2.5", hue="Month", palette=sns.color_palette("Paired"))
# # plt.show()
# plt.savefig("img/PM2.5-Month.png")

# # -------------
# # sns.set_theme(style="dark")
# # flights = sns.load_dataset("flights")
# #
# # Plot each year's time series in its own facet
# g = sns.relplot(
#     data=x_2,
#     x="Year", y="PM2.5", col="Month", hue="Month",
#     kind="line", palette="crest", linewidth=4, zorder=5,
#     col_wrap=3, height=2, aspect=1.5, legend=False,
# )
#
# # Iterate over each subplot to customize further
# for Month, ax in g.axes_dict.items():
#     # Add the title as an annotation within the plot
#     ax.text(.8, .85, Month, transform=ax.transAxes, fontweight="bold")
#
#     # Plot every year's time series in the background
#     sns.lineplot(
#         data=x_2, x="Year", y="PM2.5", units="Month",
#         estimator=None, color=".7", linewidth=1, ax=ax,
#     )
#
# # Reduce the frequency of the x axis ticks
# ax.set_xticks(ax.get_xticks()[::2])
#
# # Tweak the supporting aspects of the plot
# g.set_titles("")
# g.set_axis_labels("", "PM2.5")
# g.tight_layout()
#
# plt.show()


# 绘制散点图
# x_2 = pd.concat([x, PM], axis=1)
# for (columnName, columnData) in x_2.items():
#     print('Colunm Name : ', columnName)
#     print('Column Contents : ', columnData.values)

# scaler = StandardScaler()
# x_2["V13305"] = scaler.fit_transform(x_2[["V13305"]])


# fig, ax = plt.subplots(3, 3, figsize=(32, 18), dpi=300)
# plt.figure(figsize=(32, 18), dpi=300)
# sns.scatterplot(x='AQI', y='PM2.5', data=x_2, ax=ax[0, 0])
# sns.scatterplot(x='PM10', y='PM2.5', data=x_2, ax=ax[0, 0])
# sns.scatterplot(x='O3', y='PM2.5', data=x_2, ax=ax[0, 1])
# sns.scatterplot(x='SO2', y='PM2.5', data=x_2, ax=ax[0, 2])
# sns.scatterplot(x='NO2', y='PM2.5', data=x_2, ax=ax[1, 0])
# sns.scatterplot(x='CO', y='PM2.5', data=x_2, ax=ax[1, 1])
# sns.scatterplot(x='precipitation', y='PM2.5', data=x_2, ax=ax[1, 2])
# sns.scatterplot(x='wind_speed', y='PM2.5', data=x_2, ax=ax[2, 0])
# sns.scatterplot(x='temperature', y='PM2.5', data=x_2, ax=ax[2, 1])
# sns.scatterplot(x='humidity', y='PM2.5', data=x_2, ax=ax[2, 2])

# # plt.show()
# plt.savefig("img/scatter.png")



